/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
* This is a GIMI server module for sending Grid data over network
* The netdata format is defined in TGIMI_PROTOCOL_GRID.h
* The client for this server is named as CGridGClient
**/
#ifndef C_GRID_G_SERVER_MODULE_H_
#define C_GRID_G_SERVER_MODULE_H_

#include <inttypes.h>
#include "TGIMI_PROTOCOL_GRID.h"
#include "gimi.h"


class CGridGServerModule{
  public: 
		TGIMI_PROTOCOL_GRID_HEADER header;
		
		CGridGServerModule(gimi::GIMI *g);
		~CGridGServerModule();
		
		/**
		* Sets the header for the server
		* Must be called once before send!!
		*/
		void setHeader(TGIMI_PROTOCOL_GRID_HEADER head);
		/**
		* Set the header by components
		* Must be called once before send!!
		*/
		void setHeader(int32_t g_size, int32_t g_Nx, int32_t g_Ny, float g_resolution, 
									 unsigned char g_format, int32_t or_x, int32_t or_y);
		
		/**
		* Send grid data. The header must be set before
		* The grid is given as unsigned char buffer and the header size should be bytes 
		* 
		*/
		bool sendGrid(unsigned char *grid);
		bool sendGrid(unsigned char *grid, int32_t t_sec,int32_t t_usec);
		bool sendGrid(unsigned char *grid, float xx,float yy,float aa);
		
		/**
		* Set time to header
		*/
		void setTime(int32_t t_sec,int32_t t_usec);
		/**
		* Set the pose to header
		*/
		void setPose(float xx,float yy,float aa);
		
		void setSendParameters(int32_t sync_timeout, int32_t maxUnsynced);
		
  private:
		gimi::GIMI *gim; ///<pointer to GIMI
		bool isHeader;
		uint32_t index;
		int32_t timeout;
		int32_t maxUnsync;
		TGIMI_PROTOCOL_GRID netPacket;
		
};

#endif


